package LeetCode;

import java.util.Arrays;

public class Problem2 {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        int i = removeDuplicates(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }

    public static int removeDuplicates(int[] nums) {
        int i = 0;
        int j = i + 1;
        while (j < nums.length) {
            if (nums[i] == nums[j]) {
                j++;
            } else if (nums[i] != nums[j]) {
                nums[i+1] = nums[j];
                i++;
                j++;
            }
        }
        return i + 1;
    }
}
